let request = require("../uilts/request");

//查询用户列表数据

function getlist(page, pageSize, query) {
    // console.log(query, 66666)
    return request.get('/user/getlist', {
        params: {
            page,
            pageSize,
            query
        }
    })
}

//功能：删除某个用户
function delUser(id) {
    return request.delete('/user/remove/' + id)
}


//功能：添加新用户
function addUser(form) {
    console.log(form, 999);
    return request({
        method: 'post',
        url: 'user/adduser',
        headers: { 'Content-Type': 'multipart/form-data' },
        data: form
    })
}

//功能：查询某个用户信息
function getuser(id) {
    return request.get('/user/getuser/' + id)
}

//功能：编辑某个用户信息
function editUser(form, id) {
    return request({
        method: 'put',
        url: ('/user/reset/' + id),
        headers: { 'Content-Type': 'multipart/form-data' },
        data: form
    })
}

//功能：删除用户图片
function delUserimg(id) {
    return request({
        method: 'put',
        url: ('/user/delpic/' + id),
        headers: { 'Content-Type': 'multipart/form-data' },

    })
}

//功能：验证码生成
function getVcode(width, height, fontSize) {
    return { data } = request.get('/captcha', {
        params: {
            width,
            height,
            fontSize
        }
    })
}

//功能：登录功能
function userlogin(name, password, vcode) {
    return request.get('/user/login', {
        params: {
            name,
            password,
            vcode
        }
    })
}

//功能：修改密码
function changepsw(id, password) {
    return request.put('/user/reset', { id: id, password: password })
}

//功能：验证token有效性
function checkToken(token) {
    return request.get('/user/verify', {
        params: {
            token,
        }
    })
}

module.exports = {
    getlist,
    delUser,
    addUser,
    getuser,
    editUser,
    delUserimg,
    getVcode,
    userlogin,
    changepsw,
    checkToken,
}